package com.example.controller;


import com.example.mapper.BarsMapper;
import com.example.pojo.Bars;
import com.example.pojo.Users;
import com.example.service.IBarsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2024-06-06
 */
@RestController
@RequestMapping("/bars")
public class BarsController {
    @Resource
    private IBarsService barsService;

    @Resource
    private BarsMapper barsMapper;

    @RequestMapping("getAllBars")
    public List<Bars> getAllBars(){
        List<Bars> bars = barsService.getAllBars();
        bars.sort(Comparator.comparingInt(a -> -(a.getFc() + a.getPc())));
        return  bars;
    }

    @GetMapping("getUser")
    public List<Users> getUser(@RequestParam("uid") String uid){

        return barsService.getUser(uid);
    }

    @GetMapping("StatusChange")
    public void StatusChange(@RequestParam("bid") int bid,@RequestParam("status") int status){
        barsService.StatusChange(status,bid);
    }

    @GetMapping("getFindBars")
    public List<Bars> getFindBars(@RequestParam("select") String select,@RequestParam("input") String input){
        return barsService.getFindBars(select,input);
    }

    //首页展示的论坛人数和评论数
    @GetMapping("findBar")
    public List<Bars> FindBar(@RequestParam("tid") Integer tid){
        return barsService.FindBar(tid);
    }

    //getAllBarsByBid 单独的
    @GetMapping("getAllBarsByBid")
    public List<Bars> getAllBarsByBid(@RequestParam("bid") Integer bid){
        return barsService.getAllBarsByBid(bid);
    }

    @GetMapping("userFindBar")
    public List<Bars> userFindBar(@RequestParam("uid") Integer uid){
        return barsService.userFindBar(uid);
    }

    @GetMapping("getBarsCenter")
    public List<Bars> getBarsCenter(@RequestParam("uid") Integer uid){
        return barsService.getBarsCenter(uid);
    }

    @GetMapping("getAllApply")
    List<Bars> getAllApply(@RequestParam("bid") Integer bid){
        return  barsService.getAllApply(bid);
    }
    @GetMapping("getMyBars")
    List<Bars> getMyBars(@RequestParam("uid") Integer uid){
        return barsMapper.getMyBars(uid);
    }

    @GetMapping("addBars")
    void addBars(@RequestParam("uid") Integer uid,@RequestParam("bname") String bname,@RequestParam("tid") Integer tid,@RequestParam("bimage") String bimage){
        barsService.addBars(uid,bname,tid,bimage);
    }

    @GetMapping("delOtherid")
    void delOtherid(@RequestParam("uid") Integer uid,@RequestParam("bid") Integer bid){
        barsMapper.delOtherid(uid,bid);
    }

    @GetMapping("updateBarsApply")
    void updateBarApply(@RequestParam("uid") Integer uid,@RequestParam("bid") Integer bid,@RequestParam("otherid") String otherid){
        barsService.updateBarApply(uid,bid,otherid);
    }
}

